using System.Diagnostics;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace Edmx.Storage
{
    [DebuggerDisplay("Name={Name}, EntityType={EntityType}")]
    [XmlType(AnonymousType = true, Namespace = EdmxConstants.StorageSchemaNamespace)]
    public class EntitySet : MetadataEntityBase<EntitySet>
    {
        [XmlElement("DefiningQuery")]
        public string DefiningQuery { get; set; }

        [XmlAttribute("Name")]
        public string Name { get; set; }

        [XmlAttribute("EntityType")]
        public string EntityType { get; set; }

        private SourceType? _storeType;

        [XmlAttribute("Type", Form = XmlSchemaForm.Qualified, Namespace = EdmxConstants.StoreGeneratorNamespace)]
        public SourceType StoreType
        {
            get { return _storeType ?? SourceType.Tables; }
            set { _storeType = value; }
        }

        public bool ShouldSerializeStoreType()
        {
            return _storeType.HasValue;
        }

        [XmlAttribute("Schema")]
        public string Schema { get; set; }

        [XmlAttribute("Table")]
        public string Table { get; set; }

        [XmlAttribute("Name", Form = XmlSchemaForm.Qualified, Namespace = EdmxConstants.StoreGeneratorNamespace)]
        public string StoreName { get; set; }

        [XmlAttribute("Schema", Form = XmlSchemaForm.Qualified, Namespace = EdmxConstants.StoreGeneratorNamespace)]
        public string StoreSchema { get; set; }
    }
}